package com.origin.opengles_ndk

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import com.origin.baselibrary.activity.style.ImmersiveActivity
import com.origin.opengles_ndk.bean.TypeBean
import com.origin.opengles_ndk.databinding.ActivityOpenGlesactivityBinding
import com.origin.opengles_ndk.dialog.type_list.TypeListDialog

class OpenGLESActivity : ImmersiveActivity<ActivityOpenGlesactivityBinding>(R.layout.activity_open_glesactivity) {

//    override fun contentView(): Int = R.layout.activity_open_glesactivity
    companion object {
        init {
            System.loadLibrary("opengles_ndk")
        }
    }

    external fun stringFromJNI(): String
    private val typeBeans: MutableList<TypeBean> = mutableListOf()
    override fun pageLogical() {
        typeBeans.add(TypeBean("简单三角", 0))
        typeBeans.add(TypeBean("纹理贴图", 0))
    }

    private val onItemClickListener = object : TypeListDialog.CallDialogItem {

        override fun doCall(position: Int) {
            mGLSurfaceView.setParamsInt(position + MyGLRender.SAMPLE_TYPE)
        }
    }

    fun showType(view: View) {
        val typeListDialog =
            TypeListDialog(this)
        typeListDialog.setSizeH(500)
        typeListDialog.addAllTypeBeans(typeBeans);
        typeListDialog.setAdapterItemClick(onItemClickListener)
        typeListDialog.show()
    }


    val mGLSurfaceView: MyGLSurfaceView by lazy {
        MyGLSurfaceView(this)
    }

    override fun initContentView() {
        val lp = RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT
        )
        lp.addRule(RelativeLayout.CENTER_IN_PARENT)
        contentViewBinding.rootView.addView(mGLSurfaceView, lp)
        mGLSurfaceView.setParamsInt(MyGLRender.SAMPLE_TYPE_KEY_TRIANGLE)
    }

    override fun onDestroy() {
        super.onDestroy()
        mGLSurfaceView.unInit();
    }

}